import { filterParam } from "@/utils";
export default {
  data () {
    return {
      total: 0,
      page: 1,
      limit: 10,
      loading: false,
      searchForm: {},
      sortParams: {},
      tableParams: {},
      tableHeader: [],
      tableData: [],
      spanArr: []
    };
  },
  methods: {
    // 查询事件
    handleSearch () {
      this.page = 1;
      this.$refs.table.$children[0].clearSort();
      this.sortParams = {};
      this.getTableData();
    },
    // 获取表格参数
    getTableParams (isEmpty) {
      const opts = {
        ...this.sortParams,
        page: this.page,
        limit: this.limit
      };
      const params = Object.assign({}, this.searchForm, opts);
      params.customCode && (params.customCode = params.customCode.join(","));
      params.customCodes && (params.customCodes = params.customCodes.join(","));
      // 默认获取一周 暂时没有这个需求
      // 日期时间写死 00:00:00 - 23:59:59
      const timeArray = [["q_pageCreatedTime", "q_endCreatedTime"]];
      if (!isEmpty) {
        timeArray.map(item => {
          if (item[0] in params && item[1] in params) {
            // 初始化时间
            if (!params[item[0]] || !params[item[1]]) {
              params[item[0]] =
                this.$filters.formatDate(Date.now() - 3600 * 1000 * 24 * 6) +
                " 00:00:00";
              params[item[1]] =
                this.$filters.formatDate(Date.now()) + " 23:59:59";
            }
          }
        });
      }
      console.log('this1----params', this.tableParams)
      this.tableParams = filterParam(params);
    },
    // 排序方法
    handleSort ({ prop, order }) {
      const sortObj = {
        ascending: "ASC",
        descending: "DESC"
      };
      if (order) {
        this.sortParams = {
          order: sortObj[order],
          orderField: prop
        };
      }
      this.getTableData();
    },
    // 监听 current-page 变化
    handlePage (val) {
      this.page = val;
      this.getTableData();
    },
    // 监听 page-size 变化
    handleSize (val) {
      this.limit = val;
      this.handlePage(1);
    }
  }
};
